#define LOG_TAG "vendor.ecarx.xma.gnss@1.0-service"

#include <android/hardware/gnss/1.0/IGnss.h>
#include <hidl/LegacySupport.h>
#include <binder/ProcessState.h>

#include "Gnss.h"
#include "GnssIpcp.h"
#include "GnssPositioning.h"

using namespace android;
using namespace android::hardware;

using android::hardware::gnss::V1_0::IGnss;
using vendor::ecarx::xma::gnss::V1_0::implementation::Gnss;
using vendor::ecarx::xma::gnss::V1_0::implementation::GnssIpcp;
using vendor::ecarx::xma::gnss::V1_0::implementation::GnssPositioning;
using vendor::ecarx::xma::gnss::V1_0::implementation::IGnssPositioning;

int main() {
    android::ProcessState::initWithDriver("/dev/vndbinder");

    configureRpcThreadpool(5, true /* callerWillJoin */);

    GnssIpcp::initGnssIpcp();

    ALOGI("Registering as IGnss service...");
    auto gpsIface = std::make_unique<Gnss>(GnssIpcp::getGpsInterface());
    status_t status = gpsIface->registerAsService();

    if (status != OK) {
        ALOGE("Unable to register IGnss service (%d)", status);
        return 1;
    }

    ALOGI("Registering as IGnssPositioning service...");
    auto gnssPositioning = std::make_unique<GnssPositioning>();
    status = gnssPositioning->registerAsService();
    if (status != OK) {
        ALOGE("Unable to register IGnssPositioning service (%d)", status);
        return 1;
    }

    ALOGI("GNSS HAL Ready");
    joinRpcThreadpool();

    GnssIpcp::releaseGnssIpcp();

    ALOGI("GNSS HAL is shutting down...");
    return 1;
}
